package net.zretc.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.zretc.entitys.Pet;
import net.zretc.service.PetService;
import net.zretc.service.PetServiceImpl;

/**
 * Servlet implementation class PetAllServlet
 */
@WebServlet("/show.do")
public class PetAllServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private PetService petService=new PetServiceImpl();   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PetAllServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<Pet> list=petService.findAll();
		String flag1=request.getParameter("flag");
		boolean flag=true;
		if(flag1==null) {
			flag=false;
		}
		request.setAttribute("flag", flag);
		request.setAttribute("petlist", list);
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name=request.getParameter("name");
		List<Pet> list=petService.findByName(name);
		request.setAttribute("petlist", list);
		System.out.println(list);
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}

}
